﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcShop.Models.ViewDataModels
{
    public class UsersViewData:ViewDataBase
    {
        #region ==== Property =====
        public int PageIndex { get; set; }
        public int Count { get; set; }
        public int Total { get; set; }
        public string KeyWord { get; set; }

        public User User { get; set; }
        public IEnumerable<User> Users { get; set; }

        public Role Role { get; set; }
        public IEnumerable<Role> Roles { get; set; }

        public UserRole UserRole { get; set; }
        public IEnumerable<UserRole> UserRoles { get; set; }

        public ControllerAction ControllerAction { get; set; }
        public IEnumerable<ControllerAction> ControllerActions { get; set; }

        public ControllerActionRole ControllerActionRole { get; set; }
        public IEnumerable<ControllerActionRole> ControllerActionRoles { get; set; }

        public UserInfo UserInfo { get; set; }
        public IEnumerable<UserInfo> UserInfos { get; set; }

        public UserToRoleModel UserToRoleModel { get; set; }
        public IEnumerable<UserToRoleModel> UserToRoleModels { get; set; }

        public IEnumerable<FControllerAction> FControllerActions { get; set; }
        #endregion

        #region ==== Methods ====
        public UsersViewData WithUser(User user)
        {
            this.User = user;
            return this;
        }

        public UsersViewData WithUsers(IEnumerable<User> users)
        {
            this.Users = users;
            return this;
        }

        public UsersViewData WithRole(Role role)
        {
            this.Role = role;
            return this;
        }

        public UsersViewData WithRoles(IEnumerable<Role> roles)
        {
            this.Roles = roles;
            return this;
        }

        public UsersViewData WithUserRole(UserRole userRole)
        {
            this.UserRole = userRole;
            return this;
        }

        public UsersViewData WithUserRoles(IEnumerable<UserRole> userRoles)
        {
            this.UserRoles = userRoles;
            return this;
        }

        public UsersViewData WithControllerAction(ControllerAction controllerAction)
        {
            this.ControllerAction = controllerAction;
            return this;
        }

        public UsersViewData WithControllerActions(IEnumerable<ControllerAction> controllerActions)
        {
            this.ControllerActions = controllerActions;
            return this;
        }

        public UsersViewData WithControllerActionRole(ControllerActionRole controllerActionRole)
        {
            this.ControllerActionRole = controllerActionRole;
            return this;
        }

        public UsersViewData WithControllerActionRoles(IEnumerable<ControllerActionRole> controllerActionRoles)
        {
            this.ControllerActionRoles = controllerActionRoles;
            return this;
        }

        public UsersViewData WithUserInfo(UserInfo userInfo)
        {
            this.UserInfo = userInfo;
            return this;
        }

        public UsersViewData WithUserInfos(IEnumerable<UserInfo> userInfos)
        {
            this.UserInfos = userInfos;
            return this;
        }

        public UsersViewData WithUserToRoleModel(UserToRoleModel userToRoleModel)
        {
            this.UserToRoleModel = userToRoleModel;
            return this;
        }

        public UsersViewData WithUserToRoleModels(IEnumerable<UserToRoleModel> userToRoleModels)
        {
            this.UserToRoleModels = userToRoleModels;
            return this;
        }

        public UsersViewData WithFControllerActions(IEnumerable<FControllerAction> fControllerActions)
        {
            this.FControllerActions = fControllerActions;
            return this;
        }

        public UsersViewData WithPageIndex(int pageIndex)
        {
            this.PageIndex = pageIndex;
            return this;
        }

        public UsersViewData WithCount(int count)
        {
            this.Count = count;
            return this;
        }

        public UsersViewData WithTotal(int pageSize)
        {
            this.Total = Math.Max((this.Count + pageSize - 1) / pageSize, 1); ;
            return this;
        }

        public UsersViewData WithKeyWord(string keyWord)
        {
            this.KeyWord = keyWord;
            return this;
        }
        #endregion
    }

    public static class UsersView
    {
        public static UsersViewData Data { get { return new UsersViewData(); } }
    }
}
